//
//  FlutterViewController.swift
//  FNiOS
//
//  Created by mac on 2023/4/3.


import SwiftUI

struct CustomFlutterFragmentView : UIViewControllerRepresentable {
    
    func makeCoordinator() -> Coordinator {
        return CustomFlutterFragmentView.Coordinator(self)
    }


    func makeUIViewController(context: Context) -> some UIViewController {
        return FlutterFragmentController()
    }

    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {

    }

}

// 定义协议 类似 interface
protocol FlutterFragmentViewDelegate: NSObjectProtocol{
    func engineLoaded(_ viewController: FlutterFragmentController)
}

// 拓展
extension CustomFlutterFragmentView {

    class Coordinator : NSObject, FlutterFragmentViewDelegate{

        var mView: CustomFlutterFragmentView

        init(_ view: CustomFlutterFragmentView) {
            self.mView = view
        }

        func engineLoaded(_ viewController: FlutterFragmentController) {

        }
    }
}

class FlutterFragmentController: UIViewController {
    override func viewDidLoad(){
        super.viewDidLoad()
    }
}

struct MyView : View{
    var body :some View {
        CustomFlutterFragmentView()
            .frame(minWidth: 100, maxWidth: 120, minHeight: 50, maxHeight: 80)
    }
}

//struct FlutterViewController_Previews: PreviewProvider {
//    static var previews: some View {
//        FlutterViewController()
//    }
//}
